<?php
/**
 * 搜索引擎模型 - 核心应用
 * @author jason <yangjs17@yeah.net> 
 * @version TS3.0
 */
class StudentModel extends Model {

	protected $tableName = 'Student';
	protected	$fields	= array(
		0=>'stu_id',1=>'stu_name',2=>'gender',3=>'birthday',4=>'birth_condition',
		5=>'birth_weight',6=>'into_campus_time',7=>'school_id',8=>'class_id',9=>'family_address',
		10=>'family_name',11=>'relations',12=>'family_phone',13=>'admin_id',14=>'is_del'
	);
	//通过学生id查询学员的相关信息
	public function getstudentById($stu_id) {	
		$data=M("student")->where("stu_id=".$stu_id)->find();
		$class=M("class")->where("class_id=".$data["class_id"])->field("class_name,class_type,is_up")->find();
		if($class['is_up'] == 1) {
			if($class['class_type'] == 1) {
				$class['class_name'] = str_replace('大' , '中' , $class['class_name']);
			} elseif($class['class_type'] == 2) {
				$class['class_name'] = str_replace('中' , '小' , $class['class_name']);
			}
			$class["class_type"] = $class["class_type"] + 1 ;
		}

		$data["class_name"]=$class["class_name"];
		if($class["class_type"]==1){
			$data["class_type"]="大班";
		}else if($class["class_type"]==2){
			$data["class_type"]="中班";
		}else if($class["class_type"]==3){
			$data["class_type"]="小班";
		}else{
			$data["class_type"]="混龄班";
		}
		return $data;
	}
	//通过班级id查询学员总数
	public function getCountByClassId($id) {	
		$data=M("student")->where("class_id=".$id)->field("count(stu_id) as sum")->find();
		return $data["sum"];
	}
}